package top.lidee.module.backendApi.twice.third.wechat;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.lidee.common.dto.AccountInfo;
import top.lidee.common.service.twice.third.wechat.WechatPaySftService;
import top.lidee.common.util.TokenUtil;
import top.lidee.framework.enums.CommonExceptionEnum;
import top.lidee.framework.result.ResponseResult;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 张一恒
 * @version 1.0
 * @description: 微信收款 平台收付通（二级商户进件）
 * @date 2024/9/30 16:24
 */
@Api(tags = "微信收款 平台收付通（二级商户进件）")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/backendApi/wechatPay/sft")
public class WechatPaySftController {

    private final WechatPaySftService wechatPaySftService;


    /**
     * 电商二级商户进件（提交申请单）
     * storeId:店铺id
     * accountBank 开户银行
     * bankName 开户银行全称 （含支行）
     */
    @RequestMapping(value = "/wxIncomingParts/{storeId}", method = RequestMethod.GET)
    @ApiOperation(value = "电商二级商户进件（提交申请单）")
    public ResponseResult wxIncomingParts(@PathVariable("storeId") Integer storeId,
                                          HttpServletRequest request) {
        String token = request.getHeader("Access-Token");
        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
        if (accountInfo == null) {
            return ResponseResult.errorResult(CommonExceptionEnum.NOAUTH);
        }
        ResponseResult responseResult = wechatPaySftService.wxIncomingParts(storeId,  accountInfo);
        return responseResult;
    }


    /**
     * 对私银行调用：查询支持个人业务的银行列表API
     * next:下一页链接
     */
    @RequestMapping(value = "/callToPrivateBank", method = RequestMethod.GET)
    @ApiOperation(value = "微信对私银行调用：查询支持个人业务的银行列表API")
    public ResponseResult callToPrivateBank(@RequestParam(required = false, value = "next") String next,
                                            HttpServletRequest request) {
        String token = request.getHeader("Access-Token");
        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
        if (accountInfo == null) {
            return ResponseResult.errorResult(CommonExceptionEnum.NOAUTH);
        }
        ResponseResult responseResult = wechatPaySftService.callToPrivateBank(next, accountInfo);
        return responseResult;
    }

    /**
     * 对公银行调用：查询支持对公业务的银行列表API
     * next:下一页链接
     */
    @RequestMapping(value = "/callToPublicBank", method = RequestMethod.GET)
    @ApiOperation(value = "微信对私银行调用：查询支持个人业务的银行列表API")
    public ResponseResult callToPublicBank(@RequestParam(required = false, value = "next") String next,
                                           HttpServletRequest request) {
        String token = request.getHeader("Access-Token");
        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
        if (accountInfo == null) {
            return ResponseResult.errorResult(CommonExceptionEnum.NOAUTH);
        }
        ResponseResult responseResult = wechatPaySftService.callToPublicBank(next, accountInfo);
        return responseResult;
    }

    /**
     * 查询城市列表API
     * provinceCode:省份编码
     */
    @RequestMapping(value = "/queryTheListOfCities/{provinceCode}", method = RequestMethod.GET)
    @ApiOperation(value = "查询城市列表API")
    public ResponseResult queryTheListOfCities(@PathVariable(value = "provinceCode") String provinceCode,
                                               HttpServletRequest request) {
        String token = request.getHeader("Access-Token");
        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
        if (accountInfo == null) {
            return ResponseResult.errorResult(CommonExceptionEnum.NOAUTH);
        }
        ResponseResult responseResult = wechatPaySftService.queryTheListOfCities(provinceCode, accountInfo);
        return responseResult;
    }

    /**
     * 查询支行列表API
     * bankAliasCode:银行别名编码
     * cityCode:城市编码
     * next:下一页链接
     */
    @RequestMapping(value = "/queryTheListOfCities", method = RequestMethod.GET)
    @ApiOperation(value = "查询城市列表API")
    public ResponseResult queryBranchList(@RequestParam(value = "bankAliasCode") String bankAliasCode,
                                          @RequestParam(value = "cityCode") String cityCode,
                                          @RequestParam(value = "next", required = false) String next,
                                          HttpServletRequest request) {
        String token = request.getHeader("Access-Token");
        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
        if (accountInfo == null) {
            return ResponseResult.errorResult(CommonExceptionEnum.NOAUTH);
        }
        ResponseResult responseResult = wechatPaySftService.queryBranchList(bankAliasCode, cityCode, next, accountInfo);
        return responseResult;
    }


}
